<?php

namespace apiend\modules\shop\controllers;

use Yii;
use apiend\components\Controller;
use common\logics\ShopCategoryLogic;
use apiend\modules\shop\models\CategoryProductSearch;

/**
 * 商城分类相关接口
 * ProfileController for the `shop` module
 */
class CategoryController extends Controller {

    /**
     * Declares the allowed HTTP verbs.
     * Please refer to [[VerbFilter::actions]] on how to declare the allowed verbs.
     * @return array the allowed HTTP verbs.
     */
    protected function verbs() {
        return [
            '*' => ['GET'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actionIndex() {
        return ShopCategoryLogic::getCategoryTree();
    }

    /**
     * @inheritdoc
     */
    public function actionView($id) {
        return ShopCategoryLogic::categoryLayer($id);
    }

    /**
     * 栏目分类下的商品
     * @inheritdoc
     */
    public function actionProduct() {
        $model = new CategoryProductSearch();
        $model->load(Yii::$app->request->getQueryParams(), '');
        return $model->search();
    }

}
